﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using QuanLyVanBanBUS;

public partial class QLVB_Admin_CapNhatPhamVi : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Page.IsPostBack == false)
        {
            layMaPhamVi();

            layTenPhamVi();
        }
    }

    protected void layMaPhamVi()
    {
        string maPhamViURL = Request.QueryString["MaPhamVi"];

        PhamViBUS lvbBUS = new PhamViBUS();

        string maPhamVi = lvbBUS.layMaPhamVi(maPhamViURL);

        txtMaPhamVi.Text = maPhamVi;
    }

    protected void layTenPhamVi()
    {
        string maPhamViURL = Request.QueryString["MaPhamVi"];

        PhamViBUS lvbBUS = new PhamViBUS();

        string tenPhamVi = lvbBUS.layTenPhamVi(maPhamViURL);

        txtTenPhamVi.Text = tenPhamVi;
    }

    protected void btnCapNhat_Click(object sender, EventArgs e)
    {
        {
            PhamVi pvDTO = new PhamVi();
            pvDTO.MaPhamVi = txtMaPhamVi.Text.ToUpper();
            pvDTO.TenPhamVi = txtTenPhamVi.Text.ToUpper();

            //Kiem tra rong
            if (pvDTO.MaPhamVi.ToString() == string.Empty)
            {
                Alert.Show("Ma pham vi khong duoc rong");
                return;
            }

            if (pvDTO.TenPhamVi.ToString() == string.Empty)
            {
                Alert.Show("Ten pham vi khong duoc rong");
                return;
            }

            //Sua
            if (pvDTO.MaPhamVi.ToString() != string.Empty && pvDTO.TenPhamVi.ToString() != string.Empty)
            {
                PhamViBUS pvBUS = new PhamViBUS();

                string maPhamViURL = Request.QueryString["MaPhamVi"];

                pvBUS.suaPhamVi(pvDTO, maPhamViURL);

                Response.Redirect("ThamSoVanBan.aspx");
            }
        }
    }
    protected void btnDong_Click(object sender, EventArgs e)
    {
        Response.Redirect("ThamSoVanBan.aspx");
    }
}